<html>
<head><meta charset="utf-8"><title>MIR lint pass · t-compiler · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/index.html">t-compiler</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/MIR.20lint.20pass.html">MIR lint pass</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="197790453"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/MIR%20lint%20pass/near/197790453" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/MIR.20lint.20pass.html#197790453">(May 16 2020 at 11:06)</a>:</h4>
<p>I am looking into implementing <a href="https://github.com/rust-lang/rust/issues/46043#issuecomment-628932100">this</a>. That lint pass basically has to be implemented on MIR, so it seems I cannot use the normal lint pass infrastructure. I figured I'd follow unsafety checking, which also is on the MIR, but I cannot even properly figure out how that is invoked... it's a query, so everything is very indirect. The only call to the query is in a function called <code>mir_const</code> which I assume is for consts only. I am a bit lost here. Also I am not sure if adding a new query for my lint is really appropriate, but I'd rather not make this part of unsafety checking which is critical code and already too complicated.</p>



<a name="197790462"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/MIR%20lint%20pass/near/197790462" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/MIR.20lint.20pass.html#197790462">(May 16 2020 at 11:07)</a>:</h4>
<p>oh, found some docs which seems to indicate that <code>mir_const</code> is not just for consts. That's... a very confusingly chosen name.</p>



<a name="197790480"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/MIR%20lint%20pass/near/197790480" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/MIR.20lint.20pass.html#197790480">(May 16 2020 at 11:07)</a>:</h4>
<p>so I could just call that lint directly from <code>mir_const</code> after unsafety checking, I guess?</p>



<a name="197801699"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/MIR%20lint%20pass/near/197801699" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/MIR.20lint.20pass.html#197801699">(May 16 2020 at 15:49)</a>:</h4>
<p>clippy has MIR lints</p>



<a name="197801749"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/MIR%20lint%20pass/near/197801749" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/MIR.20lint.20pass.html#197801749">(May 16 2020 at 15:50)</a>:</h4>
<p><a href="https://github.com/rust-lang/rust-clippy/blob/0c9427309ce0c647ee32cd4c88ca5902b57fb7ee/clippy_lints/src/redundant_clone.rs#L80">https://github.com/rust-lang/rust-clippy/blob/0c9427309ce0c647ee32cd4c88ca5902b57fb7ee/clippy_lints/src/redundant_clone.rs#L80</a> is where it gets the MIR</p>



<a name="197801755"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/MIR%20lint%20pass/near/197801755" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/MIR.20lint.20pass.html#197801755">(May 16 2020 at 15:50)</a>:</h4>
<p>basically a lint that is run on all functions and processes them</p>



<a name="197801859"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/MIR%20lint%20pass/near/197801859" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/MIR.20lint.20pass.html#197801859">(May 16 2020 at 15:53)</a>:</h4>
<p>but yea, in rustc we can just create a <code>MirPass</code> that doesn't modify anything</p>



<a name="197802293"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/MIR%20lint%20pass/near/197802293" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Dylan MacKenzie (ecstatic-morse) <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/MIR.20lint.20pass.html#197802293">(May 16 2020 at 16:01)</a>:</h4>
<p>There's also the <code>unconditional_recursion</code> lint, which is run <a href="https://github.com/rust-lang/rust/blob/31add7e60709445617ab54a69f6f21cfcb2e3122/src/librustc_mir_build/build/mod.rs#L184">right after MIR building</a>. See <a href="https://github.com/rust-lang/rust/blob/master/src/librustc_mir_build/lints.rs">https://github.com/rust-lang/rust/blob/master/src/librustc_mir_build/lints.rs</a></p>



<a name="197805829"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/MIR%20lint%20pass/near/197805829" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/MIR.20lint.20pass.html#197805829">(May 16 2020 at 17:27)</a>:</h4>
<p><span class="user-mention silent" data-user-id="118594">ecstatic-morse</span> <a href="#narrow/stream/131828-t-compiler/topic/MIR.20lint.20pass/near/197802293">said</a>:</p>
<blockquote>
<p>There's also the <code>unconditional_recursion</code> lint, which is run <a href="https://github.com/rust-lang/rust/blob/31add7e60709445617ab54a69f6f21cfcb2e3122/src/librustc_mir_build/build/mod.rs#L184">right after MIR building</a>. See <a href="https://github.com/rust-lang/rust/blob/master/src/librustc_mir_build/lints.rs">https://github.com/rust-lang/rust/blob/master/src/librustc_mir_build/lints.rs</a></p>
</blockquote>
<p>interesting. so we have unsafety checking, <code>unconditional_recursion</code> and now my proposed <a href="https://github.com/rust-lang/rust/pull/72270">https://github.com/rust-lang/rust/pull/72270</a> basically all being MIR lint passes and using entirely different infrastructures...</p>



<a name="197825966"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/MIR%20lint%20pass/near/197825966" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Félix Fischer <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/MIR.20lint.20pass.html#197825966">(May 17 2020 at 02:24)</a>:</h4>
<p>I mean... it makes some sense, right?</p>



<a name="197825968"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/MIR%20lint%20pass/near/197825968" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Félix Fischer <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/MIR.20lint.20pass.html#197825968">(May 17 2020 at 02:25)</a>:</h4>
<p>At least having Clippy vs rustc to check for correctness, I think, makes sense for the sake of compile times</p>



<a name="197825973"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/MIR%20lint%20pass/near/197825973" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Félix Fischer <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/MIR.20lint.20pass.html#197825973">(May 17 2020 at 02:25)</a>:</h4>
<p>Like maybe you have a check in Clippy that is somewhat costly to run all the time</p>



<a name="197826027"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/MIR%20lint%20pass/near/197826027" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Félix Fischer <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/MIR.20lint.20pass.html#197826027">(May 17 2020 at 02:27)</a>:</h4>
<p>Now, with regards to mir lints existing at different stages of rustc... that's really intriguing. I'd guess it makes sense if we, say, can run a certain lint with less difficulty at the beginning of the MIR stage and can run another one with less difficulty at the end or middle of the MIR stage</p>



<a name="197826081"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/MIR%20lint%20pass/near/197826081" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Félix Fischer <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/MIR.20lint.20pass.html#197826081">(May 17 2020 at 02:28)</a>:</h4>
<p>Sometimes there are checks that are obvious once you look at the optimized MIR, like some code that's rejected because upon constant propagation + folding, the compiler realizes that a code assertion is being invalidated (like when dividing by 0)</p>



<a name="197826087"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/MIR%20lint%20pass/near/197826087" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Félix Fischer <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/MIR.20lint.20pass.html#197826087">(May 17 2020 at 02:28)</a>:</h4>
<p>I dunno. It's interesting tho :3</p>



<a name="197826096"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/MIR%20lint%20pass/near/197826096" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Félix Fischer <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/MIR.20lint.20pass.html#197826096">(May 17 2020 at 02:29)</a>:</h4>
<p>I didn't know there was more than one part inside the compiler where MIR lints were issued</p>



<a name="197838062"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/MIR%20lint%20pass/near/197838062" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/MIR.20lint.20pass.html#197838062">(May 17 2020 at 08:43)</a>:</h4>
<p>the three passes (unsafety checking is not a lint but a lot like it -- it doesnt modify MIR) run on basically the same MIR -- just before initial construction, just after initial construction, and just a bit after that. I don't immediately see any good reason for that. but then unsafety checking is a query and I do not understand why it should be, so there might be stuff I am missing.</p>



<a name="198254821"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/MIR%20lint%20pass/near/198254821" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Dylan MacKenzie (ecstatic-morse) <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/MIR.20lint.20pass.html#198254821">(May 20 2020 at 20:43)</a>:</h4>
<p>I looked at unsafety checking today for <a href="https://github.com/rust-lang/rust/issues/72394">#72394</a> and I don't see a good reason for it to be a query. The query is used to bundle up all the unsafety violations for closures and generators so that it can apply <code>unsafe</code> blocks from the parent item. However, I think we can assume that there is only one <code>AggregateKind::Closure</code> or <code>AggregateKind::Generator</code> per <code>DefId</code>. If that's true, we can simply recurse when we see it instead of storing the results in the query table. </p>
<p>I suppose the downside is that unsafety checking would depend on <code>mir_built</code> for both the parent item and the closure, whereas it only depends on <code>unsafety_check_result</code> for the closure today.</p>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>